```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Map集合详解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #f5f7fa;
            border-left: 4px solid #6e8efb;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            background-color: #fff9c4;
            padding: 0.1rem 0.3rem;
            border-radius: 0.2rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">深入理解Java Map集合</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索键值存储的核心原理与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <a href="#why-map" class="px-6 py-3 bg-white text-indigo-600 rounded-lg font-medium hover:bg-gray-100 transition">开始学习</a>
                <a href="#visualization" class="px-6 py-3 border-2 border-white rounded-lg font-medium hover:bg-white hover:bg-opacity-10 transition">数据可视化</a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-12 px-4">
        <!-- Why Map Section -->
        <section id="why-map" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-500 mr-4"></div>
                <h2 class="text-3xl font-bold">为什么需要使用Map？</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card mb-8">
                <div class="p-6">
                    <p class="text-lg mb-6">Map在Java集合框架中扮演着至关重要的角色，它提供了一种高效的键值对存储机制，解决了我们需要通过唯一标识快速访问数据的场景。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-blue-50 p-6 rounded-lg">
                            <h3 class="text-xl font-semibold mb-3 text-blue-700 flex items-center">
                                <i class="fas fa-key mr-2"></i>Map核心特性
                            </h3>
                            <ul class="space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>存储键值对(key-value)结构数据</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>键(key)不允许重复，保证唯一性</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>通过哈希机制实现高效查找</span>
                                </li>
                            </ul>
                        </div>
                        
                        <div class="bg-purple-50 p-6 rounded-lg">
                            <h3 class="text-xl font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-project-diagram mr-2"></i>与Set的关系
                            </h3>
                            <p>Set底层实际上也是使用Map实现的(将值作为Map的key)，因此同样具有元素唯一的特性。主要区别在于Set只存储单个元素，而Map存储键值对。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Map Methods Section -->
        <section id="map-methods" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-blue-500 mr-4"></div>
                <h2 class="text-3xl font-bold">掌握Map的常用方法</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card mb-8">
                <div class="p-6">
                    <div class="overflow-x-auto">
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781220662-069fd251-2da6-4758-b84a-9983c2f4e2b5.png" 
                             alt="Map常用方法图示" 
                             class="w-full rounded-lg border border-gray-200">
                    </div>
                    
                    <div class="mt-8 grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2">核心方法</h3>
                            <ul class="space-y-3">
                                <li><span class="font-medium">put(key, value):</span> 添加键值对</li>
                                <li><span class="font-medium">get(key):</span> 根据键获取值</li>
                                <li><span class="font-medium">remove(key):</span> 删除指定键的映射</li>
                                <li><span class="font-medium">containsKey(key):</span> 检查是否包含指定键</li>
                                <li><span class="font-medium">keySet():</span> 获取所有键的集合</li>
                            </ul>
                        </div>
                        
                        <div>
                            <h3 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2">遍历方式</h3>
                            <div class="code-block p-4 rounded-lg mb-4">
                                <pre><code>// 方式1: 通过键集合遍历
for (String key : map.keySet()) {
    System.out.println(key + ": " + map.get(key));
}

// 方式2: 通过Entry遍历(推荐)
for (Map.Entry&lt;String, String&gt; entry : 
        map.entrySet()) {
    System.out.println(entry.getKey() + ": " 
        + entry.getValue());
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- HashMap Section -->
        <section id="hashmap" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-green-500 mr-4"></div>
                <h2 class="text-3xl font-bold">深入分析HashMap的存储</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card mb-8">
                <div class="p-6">
                    <div class="mb-6">
                        <h3 class="text-xl font-semibold mb-3 text-gray-800">键的唯一性机制</h3>
                        <p>HashMap通过<code class="highlight">hashCode()</code>和<code class="highlight">equals()</code>方法来确保键的唯一性：</p>
                        <ol class="list-decimal pl-6 mt-4 space-y-2">
                            <li>先比较hashCode是否相同</li>
                            <li>如果hashCode相同，再调用equals方法比较</li>
                            <li>两者都相同则认为键重复</li>
                        </ol>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-medium mb-2">使用JDK类型作为key</h4>
                            <div class="code-block p-4 rounded-lg">
                                <pre><code>Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
map.put("name", "张三");
map.put("age", "25");</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium mb-2">使用自定义类型作为key</h4>
                            <div class="code-block p-4 rounded-lg">
                                <pre><code>class Student {
    private String id;
    // 必须重写hashCode和equals
    @Override
    public int hashCode() { ... }
    @Override
    public boolean equals(Object o) { ... }
}

Map&lt;Student, String&gt; map = new HashMap&lt;&gt;();</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- LinkedHashMap Section -->
        <section id="linkedhashmap" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-yellow-500 mr-4"></div>
                <h2 class="text-3xl font-bold">LinkedHashMap（了解）</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-6">
                    <div class="flex items-start">
                        <div class="bg-yellow-100 p-3 rounded-full mr-4">
                            <i class="fas fa-info-circle text-yellow-600 text-xl"></i>
                        </div>
                        <div>
                            <p>LinkedHashMap继承自HashMap，通过维护一个双向链表来记录元素的插入顺序或访问顺序，因此它能够保持元素的<strong>插入顺序</strong>或<strong>访问顺序</strong>，这是它与HashMap的主要区别。</p>
                        </div>
                    </div>
                    
                    <div class="mt-6 code-block p-4 rounded-lg">
                        <pre><code>// 保持插入顺序
Map&lt;String, String&gt; linkedMap = 
    new LinkedHashMap&lt;&gt;();
linkedMap.put("name", "张三");
linkedMap.put("age", "25");
// 遍历顺序与插入顺序一致</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- TreeMap Section -->
        <section id="treemap" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-red-500 mr-4"></div>
                <h2 class="text-3xl font-bold">深入分析TreeMap的存储</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card mb-8">
                <div class="p-6">
                    <p class="mb-6">TreeMap基于红黑树实现，能够自动对键进行排序。它要求键必须实现<code class="highlight">Comparable</code>接口，或者在构造时提供<code class="highlight">Comparator</code>。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-medium mb-2">使用JDK类型作为key</h4>
                            <div class="code-block p-4 rounded-lg">
                                <pre><code>// String和Integer已实现Comparable
TreeMap&lt;String, String&gt; treeMap = 
    new TreeMap&lt;&gt;();
treeMap.put("name", "张三");
treeMap.put("age", "25");
// 按键的自然顺序排序</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium mb-2">使用自定义类型作为key</h4>
                            <div class="code-block p-4 rounded-lg">
                                <pre><code>class Student implements Comparable&lt;Student&gt; {
    private String id;
    @Override
    public int compareTo(Student s) {
        return this.id.compareTo(s.id);
    }
}

TreeMap&lt;Student, String&gt; treeMap = 
    new TreeMap&lt;&gt;();</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section id="visualization" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-purple-500 mr-4"></div>
                <h2 class="text-3xl font-bold">Map家族关系图</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-6">
                    <div class="mermaid">
                        classDiagram
                            class Map {
                                <<interface>>
                                +put(K key, V value)
                                +get(Object key)
                                +remove(Object key)
                                +keySet()
                                +entrySet()
                            }
                            
                            class AbstractMap {
                                <<abstract>>
                            }
                            
                            class HashMap {
                                +HashMap()
                                +HashMap(int initialCapacity)
                                +HashMap(Map<? extends K,? extends V> m)
                            }
                            
                            class LinkedHashMap {
                                +LinkedHashMap()
                                +LinkedHashMap(int initialCapacity)
                                +LinkedHashMap(Map<? extends K,? extends V> m)
                            }
                            
                            class TreeMap {
                                +TreeMap()
                                +TreeMap(Comparator<? super K> comparator)
                                +TreeMap(Map<? extends K,? extends V> m)
                            }
                            
                            Map <|-- AbstractMap
                            AbstractMap <|-- HashMap
                            HashMap <|-- LinkedHashMap
                            AbstractMap <|-- TreeMap
                    </div>
                </div>
            </div>
        </section>

        <!-- Extension Section -->
        <section id="extension" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-500 mr-4"></div>
                <h2 class="text-3xl font-bold">扩展思考</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-6">
                    <div class="flex items-start mb-6">
                        <div class="bg-red-100 p-3 rounded-full mr-4">
                            <i class="fas fa-exclamation-triangle text-red-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">并发修改异常问题</h3>
                            <p>下面的代码会抛出<code class="highlight">ConcurrentModificationException</code>异常，因为在迭代过程中修改了集合结构。</p>
                        </div>
                    </div>
                    
                    <div class="code-block p-4 rounded-lg mb-6">
                        <pre><code>List&lt;String&gt; list = new ArrayList&lt;&gt;();
list.add("111");
list.add("222");
Iterator&lt;String&gt; it = list.iterator();
while(it.hasNext()){
    System.out.println(it.next());
    list.add("444"); // 这里会抛出异常
}</code></pre>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-medium mb-2 text-blue-700">解决方案：使用并发集合</h4>
                        <p>对于需要在迭代过程中修改集合的场景，可以使用<code class="highlight">CopyOnWriteArrayList</code>等并发集合类，它们通过创建底层数组的副本来实现线程安全。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Homework Section -->
        <section id="homework" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-teal-500 mr-4"></div>
                <h2 class="text-3xl font-bold">作业练习</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">学生成绩管理系统</h3>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-medium mb-2 border-b pb-2">基础要求</h4>
                            <p>给定6名学生的考试分数录入到Map中，以学号作为key，分数作为value：</p>
                            <ul class="list-disc pl-6 mt-2 space-y-1">
                                <li>打印该6名学生及对应的分数</li>
                                <li>假设分数不存在重复</li>
                            </ul>
                            
                            <div class="mt-4 code-block p-4 rounded-lg">
                                <pre><code>Map&lt;String, Integer&gt; scores = new HashMap&lt;&gt;();
scores.put("S001", 85);
scores.put("S002", 92);
// 添加更多学生...
scores.forEach((id, score) -&gt; 
    System.out.println(id + ": " + score));</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium mb-2 border-b pb-2">进阶要求(选做)</h4>
                            <p>按分数显示前三名学员学号与成绩：</p>
                            <ul class="list-disc pl-6 mt-2 space-y-1">
                                <li>处理可能存在相同分数的情况</li>
                                <li>综合运用Map、List、Set</li>
                                <li>使用Collections工具类进行排序</li>
                            </ul>
                            
                            <div class="mt-4">
                                <img src="https://cdn.nlark.com/yuque/0/2023/bmp/21449790/1692781221712-4c08c44c-7250-4fef-8c78-b5255665b4d6.bmp" 
                                     alt="有重复分数的输出示例" 
                                     class="w-full rounded-lg border border-gray-200">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center">
                <h3 class="text-xl font-semibold mb-2">技术小馆</h3>
                <p class="text-gray-400">分享前沿技术，传播编程智慧</p>
                <div class="mt-6">
                    <a href="http://www.yuque.com/jtostring" 
                       class="text-blue-400 hover:text-blue-300 transition underline">
                        www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
            }
        });
    </script>
</body>
</html>
```